<cfif not IsDefined("expid")>
	<cfset session.message="No experiment specified">
	<cflocation url="/ecada/index.cfm">
</cfif>

<cfinclude template="/ecada/header.cfm">

<cfquery datasource="exp" name="experiments">
    	select * 
    	from givesanswer, trial 
    	where trial.expid=#expid#
    	and givesanswer.trialid = trial.id
</cfquery>
    
    
<cfquery datasource="exp" name="experimentscorrect">
    	select condid, trial.id, stimuli.answer
    	from stimuli, trial
    	where #expid# =  trial.expid
    	and stimid = stimuli.id
    	order by condid
    </cfquery>

<cfoutput>

<h1>Charts per Condition</h1>

<cfquery datasource="exp" name="condinfo">
    	select conditions.id, conditions.description 
    	from conditions, experiment 
    	where experiment.id=#expid#
    	and conditions.expid=experiment.id
    </cfquery>




<!---START OF DETAIL--->

<cfchart format="flash" scalefrom="0" scaleto="100" chartWidth="600" showborder="yes" labelformat="number" xaxistitle="Condition" yaxistitle="Percent incorrect" tipstyle="mouseOver" title="Percent incorrect Answers per Condition">
<cfchartseries type="bar" seriescolor="red">
<cfloop query="condinfo">

<cfquery datasource="exp" name="numcorrect">
select stimuli.answer as correctanswer, givesanswer.answer as givenanswer
from givesanswer, trial, stimuli 
where givesanswer.trialid=trial.id
and trial.stimid=stimuli.id
and condid=#id#
</cfquery>

<cfset totincorrect=0>
<cfloop query="numcorrect">
<cfif #trim(correctanswer)# neq #trim(givenanswer)#>
	<cfset totincorrect = totincorrect+1>
</cfif>
</cfloop>


<cfquery datasource="exp" name="totalnum">
select count(*) as cnt
from givesanswer, trial, stimuli 
where givesanswer.trialid=trial.id
and trial.stimid=stimuli.id
and condid=#id#
</cfquery>

condition #description# #totincorrect# #totalnum.cnt#<br>

<cfset percentage = ArrayNew(1)>
<cfset percent = #totincorrect# *100 / #totalnum.cnt#>
#percent#
<cfset #ArrayAppend(percentage, percent)#>




<cfchartdata item="#description#" value="#percent#" />

</cfloop>
</cfchartseries>
</cfchart>

<!--- new chart for timing --->

<cfchart format="flash" scalefrom="0" scaleto="1" chartWidth="600" showborder="yes" labelformat="number" xaxistitle="Condition" yaxistitle="Average Time" tipstyle="mouseOver" title="Average Time per Condition">
<cfchartseries type="bar" seriescolor="blue">
<cfloop query="condinfo">

<cfquery datasource="exp" name="timing">
    	select participantid, hour, minute, second, hour2, minute2, second2 
    	from givesanswer,trial, stimuli 
    	where expid = #expid# 
    	and givesanswer.trialid=trial.id
    	and stimuli.id=trial.stimid

    	and condid = #id#
    </cfquery>

<cfset total = 0>
<cfloop query="timing">
<cfset times = ArrayNew(1)>
<cfset condid = ArrayNew(1)>
    <cfset MyTime="#hour#:#minute#:#second#">  
<cfset MyAnotherTime="#hour2#:#minute2#:#second2#">    
<cfset MyDateTime=CreateDateTime(Year(Now()),Month(Now()),Day(Now()),#hour#,#minute#,#second#)>  
<cfset MyDateTime2=CreateDateTime(Year(Now()),Month(Now()),Day(Now()),#hour2#,#minute2#,#second2#)>  
<cfset ArrayAppend(times, DateDiff("s", "#MyDateTime#", "#MyDateTime2#"))>
<cfset total = total + DateDiff("s", "#MyDateTime#", "#MyDateTime2#")>
<cfset ArrayAppend(condid, "#condinfo.description#")>
</cfloop>

<cfset ave = total/ArrayLen(times)>


<cfchartdata item="#description#" value="#ave#" />
 

 <!---<cfchartseries type="line" query="centralSales" itemcolumn="year" valuecolumn="annualSales" serieslabel="Central" seriescolor="66CCCC" markerstyle="diamond" />
       <cfchartseries type="line" query="westCoastSales" itemcolumn="year" valuecolumn="annualSales" serieslabel="West Coast" seriescolor="66CCFF" markerstyle="rectangle" />--->

</cfloop>
</cfchartseries>
</cfchart>
</cfoutput> 

<cfinclude template="/ecada/footer.cfm">
